package core.util.database.attribute;

import java.util.Iterator;
import java.util.List;

import core.attribute.model.Attribute;
import core.attribute.model.AttributeSet;
import core.product.model.Product;
import backend.attribute.manager.AttributeSetManager;
import backend.product.manager.ProductAttributeSetManager;
import backend.product.manager.ProductManager;

public class AssignAttributeSetToAllProduct {

	/**
	 * @param args
	 */
	public static void assignAttributeSet(String attributeSet)
	{
		ProductManager pm = new ProductManager();
		AttributeSetManager asm = new AttributeSetManager();
		ProductAttributeSetManager pasm = new ProductAttributeSetManager();
		
		List<Product> products = pm.getProductList();
		Iterator<Product> prodItr = products.iterator();
		AttributeSet as = asm.getAttributeSetByName(attributeSet);
		
		while(prodItr.hasNext())
		{
			Product p = prodItr.next();
			Iterator<Attribute> aItr = as.getAttributes().iterator();
			while(aItr.hasNext())
			{
				Attribute a = aItr.next();
				pasm.assignAttributeSet(p, as, a);
			}
		}
		
	}
	public static void main(String[] args) 
	{
		// TODO Auto-generated method stub
		//	assignAttributeSet("General");
		assignAttributeSet("Attractions");

	}

}
